#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/5/13 10:50
# @USER    : 717-3
# @File    : MedianOfTwoArrays.py
# @Software: PyCharm
# @Version  : Python-3.6
# @TASK:Median of Two Sorted Arrays
from typing import List

class Solution:
    def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
        """
        There are two sorted arrays nums1 and nums2 of size m and n respectively.
        Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
        You may assume nums1 and nums2 cannot be both empty.

        :param nums1: list
        :param nums2: list
        :return: median

        Example 1:
            nums1 = [1, 3]

            nums2 = [2]

            The median is 2.0

        Example 2:
            nums1 = [1, 2]

            nums2 = [3, 4]

            The median is (2 + 3)/2 = 2.5
        """
        nums1.extend(nums2)
        nums1.sort()
        return (nums1[len(nums1) // 2] + nums1[- (len(nums1) // 2) - 1]) / 2 if nums1 else False


if __name__ == '__main__':
    # Q4
    S = Solution()
    n1 = [3]
    n2 = [-2, -1]
    print(S.findMedianSortedArrays(n1, n2))
    print('done')
